<template>
    <div>
        <div class="container">
            <div class="admin-index">
                <div>
                    <div class="e-p-b-30" style="font-size: 18px;">库存表</div>
                    <el-radio-group v-model="dataType" class="e-m-b-45">
                        <el-radio-button label="0">数据中台</el-radio-button>
                        <el-radio-button label="1">库存表</el-radio-button>
                        <el-radio-button label="2">线上回收统计</el-radio-button>
                        <el-radio-button label="3">门店回收统计</el-radio-button>
                        <el-radio-button label="4">小哥入库统计</el-radio-button>
                        <el-radio-button label="5">出库销售统计</el-radio-button>
                    </el-radio-group>
                </div>
                <div>
                    <el-form :inline="true" class="demo-form-inline">
                        <el-form-item label="所属加盟商">
                            <franchiseList v-model="listFranchiseId" :firstSelect="true" @change="selectFranchise"></franchiseList>
                        </el-form-item>
                        <el-form-item label="回收小哥">
                            <userList v-model="brotherId" :franchiseId="listFranchiseId" @change="selectUser" v-if="!loadingUserData"></userList>
                        </el-form-item>
                        <!-- <el-form-item label="条件筛选">
                            <el-cascader
                                :options="optionlist"
                                :props="{ checkStrictly: true }"
                                clearable 
                                filterable
                                @change="selectFilter">
                            </el-cascader>
                        </el-form-item> -->
                    </el-form>
                </div>
                <div class="flex">
                    <div class="e-flex-1">
                        <!-- 线上回收统计 -->
                        <statistics-recycle-online ref="online" :franchiseId="listFranchiseId" :brotherId="brotherId"></statistics-recycle-online>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import franchiseList from '@/components/form-select-type/franchiseList.vue'
import userList from '@/components/form-select-type/userList.vue'
export default {
    layout: 'admin',
    components: {
        franchiseList,
        userList
    },
    data() {
        return {
            loading: false,
            dataType: 2,
            tableData: [],
            listFranchiseId: null,
            brotherId: null,
            loadingUserData: false,
            optionlist: []
        };
    },
    watch: {
        dataType(val) {
            console.log(val)
            let type = Number(val)
            switch (type) {
                case 0:
                    this.$router.push({
                        path: '/'
                    })
                    break;
                case 1:
                    this.$router.push({
                        path: '/statistics/inventory'
                    })
                    break;
                case 2:
                    this.$router.push({
                        path: '/statistics/online'
                    })
                    break;
                case 3:
                    this.$router.push({
                        path: '/statistics/store'
                    })
                    break;
                case 4:
                    this.$router.push({
                        path: '/statistics/onlinestorage'
                    })
                    break;
                case 5:
                    this.$router.push({
                        path: '/statistics/storeSell'
                    })
                    break;
            }
        }
    },
    mounted() {
        this.getOnlineOption()
    },
    methods: {
        selectFilter(value){
            console.log('选择线上回收数据搜索选项',value)
            if(value.length > 0) this.listFranchiseId = value[0]
            if(value.length > 1) {
                this.brotherId = value[1]
            }else{
                this.brotherId = null
            }
            setTimeout(() => {
                this.$refs.online.getList()
            }, 100)
        },
        getOnlineOption() {
            this.$axios.post('/Statistics/Recycle/OnlineOption',{}).then((res)=>{
                this.optionlist = []
                let array = []
                res.forEach((item,index)=>{
                    array.push({
                        value: item.id,
                        label: item.name,
                        children: []
                    })
                    if(item.brotherlist.length > 0){
                        item.brotherlist.forEach((cell,i)=>{
                            array[index].children.push({
                                value: cell.id,
                                label: cell.name,
                                // children: []
                            })
                            // if(cell.stafflist.length > 0){
                            //     cell.stafflist.forEach((con)=>{
                            //         array[index].children[i].children.push({
                            //             value: con.id,
                            //             label: con.name,
                            //         })
                            //     })
                            // }
                        })
                    }
                })
                console.log('格式化后的线上回收数据搜索选项',array)
                this.optionlist = array
            })
        },
        // 选择加盟商
        selectFranchise(value){
            this.loadingUserData = true
            this.loading = true
            this.listFranchiseId = value
            this.brotherId = null
            setTimeout(() => {
            	this.loading = false
                this.loadingUserData = false
                console.log('listFranchiseId',this.listFranchiseId)
                this.$refs.online.getList()
            }, 100)
        },
        // 选择店员
        selectUser(value){
            this.loading = true
            this.brotherId = value,
            setTimeout(() => {
            	this.loading = false
                this.$refs.online.getList()
            }, 100)

        },
        downloadwithdrawa() {
            this.$axios.post('/Statistics/Recycle/OnlineDownload', {
                
            }, {
                responseType: 'blob'
            }).then(res => {
                console.log(res)
                let content = res;
                let fileName = '库存表.xls'
                this.utils.saveAndExport(content, fileName)
            })
        },
        // getstorelist() {
        //     this.$axios.post('/Select/StoreList', {
        //         "pageIndex": 1,
        //         "pageSize": 999,
        //     }).then((res) => {
        //         console.log(res)
        //         this.StoreList = res.rows
        //         // this.StoreList.unshift({
        //         // 	id: "",
        //         // 	name: '全部'
        //         // })
        //     }).catch((err) => {
        //         this.loading = false
        //     })
        // },
    }
};
</script>
<style lang="scss" scoped></style>